class xT_AICommand_Act_PatrolPosition extends xT_AICommand_Act;

var private array<xT_Marker_PatrolPoint>        PatrolPoints;
var private int                                 PatrolCount;


//=============================================================================
// State
//=============================================================================
AUTO state PatrolPosition
{
	function GetPatrolRoute()
	{
		local xT_Marker_PatrolPoint lRoutePoint;

		ForEach WorldInfo.AllNavigationPoints(class'xT_Marker_PatrolPoint', lRoutePoint)
		{
			if (lRoutePoint.ActorRouteFor == pawn) PatrolPoints.AddItem(lRoutePoint);
		}
	}

	function GenerateRoute()
	{
		local xT_Marker_PatrolPoint lRoutePoint;
		local int il, jl;

		for(il=0; il < PatrolPoints.Length; il++)
		{
			for(jl=0; jl < PatrolPoints.Length; jl++)
			{
				if (PatrolPoints[il].RouteParameter > PatrolPoints[jl].RouteParameter)
				{
					lRoutePoint = PatrolPoints[il];
					PatrolPoints[il] = PatrolPoints[jl];
					PatrolPoints[jl] = lRoutePoint;
				}
			}
		}


		//test
		for(il=0; il < PatrolPoints.Length; il++)
		{
			`log("PatrolPoints : "$PatrolPoints[il]);
		}
	}

Begin:
	//`log("xT_AICommand_PatrolPosition executed");

Prepare:
	GetPatrolRoute();
	if (PatrolPoints.Length <= 0) popcommand(self);
	GenerateRoute();
	Sleep(Worldinfo.DeltaSeconds);

ForwardPatroling:
	For (PatrolCount = 0; PatrolCount < PatrolPoints.Length; PatrolCount++)
	{
		MoveToward(PatrolPoints[PatrolCount], none, Pawn.GetCollisionRadius(), false, true);
		Sleep(Frand());
	}

BackwardPatroling:
	For (PatrolCount = 0; PatrolCount < PatrolPoints.Length; PatrolCount++)
	{
		MoveToward(PatrolPoints[PatrolPoints.Length - PatrolCount - 1], none, Pawn.GetCollisionRadius(), false, true);
		Sleep(Frand());
	}

Ending:
	Goto('ForwardPatroling');
}

//=============================================================================
// DefaultProperties
//=============================================================================
defaultproperties
{
}
